<?php 
//print_r($_POST);
//require_once TEMPLATEPATH.'/views/process/process-box-search.php';
if(isset($_GET['hidden_current_search']) && $_GET['hidden_current_search']!='')
{
	$hidden_current_search = $_GET['hidden_current_search'];
}

if(is_search())
{
	$_SESSION['search_info'] = $_GET;
	$keyword = $_SESSION['search_info']['s'];
	$citys = $_SESSION['search_info']['citys'];
	$districts = $_SESSION['search_info']['districts'];
	$prices = $_SESSION['search_info']['prices'];
	$styles = $_SESSION['search_info']['styles'];

}
?>

<?php 
$args = null;

$args = array('title_li'  => '','orderby' => 'id','taxonomy' => 'khu-vuc','parent' =>0,'hide_empty' => 0,'hierarchical'  => true,'depth'  => 1);
$khuvuc_list = get_categories($args);
//print_r($khuvuc_list);
## loai dia oc
$args = null;
$args = array('title_li'  => '','orderby' => 'id','taxonomy' => 'hang-muc','hide_empty' => 0,'hierarchical'  => true,'depth'  => 1);
$hangmuc_list = get_categories($args);

## xu ly cac khoang gia
if($hidden_current_search!='' || $current_search=='can-ban')
	$about_prices1 = get_option("mySetting_about_price_sales");
else 
	$about_prices1 = get_option("mySetting_about_price");	
	
$about_prices = explode(",",$about_prices1);


## danh sach quan huyen 
$args = array('title_li'  => '','orderby' => 'id','taxonomy' => 'khu-vuc','hide_empty' => 0,'parent' => 0,'hierarchical'  => true,'depth'  => 1);
$quanhuyen_list = get_categories($args);
foreach ($quanhuyen_list as $value) 
{	
	$args5 = array('title_li'  => '','orderby' => 'id','taxonomy' => 'khu-vuc','hide_empty' => 0,'child_of' => $value->term_id,'hierarchical'  => true,'depth'  => 1);
	$khuvuc_list5 = get_categories($args5);
	$mystring ='';
	$mystring_title = '';
	foreach ($khuvuc_list5 as $value5) 
	{
		$mystring.= $value5->slug.',';	
		$mystring_title.= $value5->name.',';
	} 
	if($mystring!='')
	{
	?>
		<input type="hidden" name="<?php echo $value->slug;?>" title="<?php echo $mystring_title;?>" id="<?php echo $value->slug;?>" value="<?php echo $mystring;?>">
	<?php
	}
	$mystring ='';
	$khuvuc_list5 = null;
}
$quanhuyen_list = null;
?>



<div class="search">
      <div class="bg_left"></div>
      <div class="bg_center">
        <div class="search_content">
          <div class="left_search_content">
            <ul>
              <li class="btn_forent <?php echo $mn_chothue;?>"><a href="<?php echo WP_MYSITE_URL;?>/cho-thue"></a></li>
              <li class="btn_for_sale <?php echo $mn_canban;?>"><a <?php echo $mn_canban2;?> href="<?php echo WP_MYSITE_URL;?>/can-ban"></a></li>
            </ul>
          </div>
          <!-- end .left_search_content-->
          <div class="bg_search_content"> </div>
          <!-- end .bg_search_conten-->
          <div class="right_search_content">
            <div class="search_box">
              <div class="title_search"><span>Tìm kiếm ĐỊA ỐC
              <?php 
              if($hidden_current_search!='' || $current_search!=null)
              {
              	echo 'Cần bán';
              }
              else 
              {
              	echo  'Cho thuê';
              }
              ?>
              </span></div>
              <div class="formsearch_box">
                <form class="form" action="<?php echo WP_MYSITE_URL;?>" method="get" name="form_name">
                  <div class="bg_text_box">
                    <input class="text" id="s" name="s" type="text" onblur="if(this.value=='')this.value='Nhập từ khóa tìm kiếm...'" onfocus="if(this.value=='Nhập từ khóa tìm kiếm...')this.value=''" value="<?php if($keyword) echo $keyword; else echo 'Nhập từ khóa tìm kiếm...';?>" size="30" />
                    <?php 
                    if($hidden_current_search!='' || $current_search!=null)
                    {
                    ?>
                    <input type="hidden" name="hidden_current_search" id="hidden_current_search" value="<?php if($hidden_current_search!='') echo $hidden_current_search; else  echo $current_search;?>">
                    <?php 	
                    }
                    ?>
                    
                  </div>
                  <div class="clr"></div>
                  <div class="note">Nhập vào tên của địa ốc... 
                  <!-- 
                  <input name="chon_hinh_thuc" type="radio" value="can-ban"> Cần bán &nbsp;
                  <input name="chon_hinh_thuc" type="radio" checked="checked" value="cho-thue"> Cho thuê &nbsp;
                  -->
                  </div>
                  <div class="cbo_search">
                    <div class="select_1">
                      <select class="select" name="citys" id="citys" onchange="swapOpts(this.options[selectedIndex].text);">
                        <option value="chon-tinh-thanh-pho">Chọn tỉnh/thành phố</option>
                        <?php 
                        foreach ($khuvuc_list as $value) 
                        {
                        	if($citys && $citys==$value->slug)
                        	{
                        	?>
	                        <option selected="selected" value="<?php echo $value->slug;?>"><?php echo $value->name;?></option>
	                        <?php	
                        	}
                        	else 
                        	{
                        	?>
	                        <option value="<?php echo $value->slug;?>"><?php echo $value->name;?></option>
	                        <?php	
                        	}                         	
                        }
                        $khuvuc_list = null;
                        ?>
                      </select>
                    </div>
                    
                    <!--  xu ly phan quan huyen theo tinh-thanh-pho -->                    
                    
                    <div class="select_1">                    	
                      <select class="select" name="districts" id="districts">
                        <option value="chon-quan-huyen">Chọn quận/huyện</option>
                        
                      </select>
                    </div>
                    <div class="clr"></div>
                    <div class= "div10"></div>
                    <div class="select_1">
                      <select class="select" name="prices" id="prices">
                        <option value="chon-khoang-gia">Chọn khoảng giá</option>
                        <?php 
                        foreach ($about_prices as $value) 
                        {  
                        	$newvalue = explode("-", $value);
                        	//Xoa het cac khoang trang
                        	$c_value = str_ireplace(' ','', $value);
                        	$c_session = str_ireplace(' ','',$_SESSION['search_info']['prices']);
                        	
                        	if($c_value == $c_session)
                        	{
                        		
                        	?>
	                        <option selected="selected" value="<?php echo $newvalue[0].' - '.$newvalue[1];?>"><?php echo db_xuly_donvigia($newvalue[0]).' - '.db_xuly_donvigia($newvalue[1]);?></option>
	                        <?php	
                        	}
                        	else 
                        	{
                        	?>
	                        <option value="<?php echo $newvalue[0].' - '.$newvalue[1];?>"><?php echo db_xuly_donvigia($newvalue[0]).' - '.db_xuly_donvigia($newvalue[1]);?></option>
	                        <?php	
                        	}                        
                        }  
                        $about_prices = null;                      
                        ?>
                      </select>
                    </div>
                    <div class="select_1">
                      <select class="select" name="styles" id="styles">
                        <option value="chon-loai-dia-oc">Chọn loại địa ốc</option>
                        <?php 
                        foreach ($hangmuc_list as $value) 
                        {
                        	if($styles && $styles== $value->slug)
                        	{
                        	?>
	                        <option selected="selected" value="<?php echo $value->slug;?>"><?php echo $value->name;?></option>
	                        <?php 	
                        	}
                        	else 
                        	{
                        	?>
	                        <option value="<?php echo $value->slug;?>"><?php echo $value->name;?></option>
	                        <?php 	
                        	}                        	
                        }
                        $hangmuc_list = null;
                        ?>
                      </select>
                    </div>
                    <input type="submit" value="" id="btn_search_send_request"/>
                  </div>
                  <!-- end .cbo_search-->
                </form>
              </div>
              <!-- end .formsearch_box-->
            </div>
            <!-- end .search_box-->
          </div>
          <!-- end .right_search_conten-->
        </div>
        <!-- end .search_content-->
      </div>
      <!-- end .bg_center-->
      <div class="bg_right"></div>
    </div>